//
//  DetailView.m
//  Dear
//
//  Created by n22 on 15/7/15.
//  Copyright (c) 2015年 陈俊俊. All rights reserved.
//

#import "SDetailView.h"
#import "UIImageView+WebCache.h"
@implementation SDetailView
- (void)awakeFromNib{
    self.scrollView.pagingEnabled = YES;
    self.scrollView.showsHorizontalScrollIndicator = NO;
    self.scrollView.showsVerticalScrollIndicator = NO;
}

- (void)setModel:(SexModel *)model
{
    CGFloat totalHeight = 0;
    self.titleLabel.numberOfLines = 0;
    self.titleLabel.text = model.title;
    
    CGFloat titleH = 0;
    if (self.contentLabel.text.length > 0) {
        titleH = [CJJHelper textHeightFromString:self.titleLabel.text width:ScreenSize.width - 20 fontSize:17];
    }
    self.titleH.constant = titleH + 10;
    totalHeight += titleH +20;
    
    self.dateLabel.text = [NSString stringWithFormat:@"%@  %@",[CJJHelper dateStringFormNumberString: [model.dt_create stringValue]],model.source];
    
    self.contentLabel.text = model.content;
   
    if (model.bigpicture.length > 0) {
        NSArray *bigs = [model.bigpicture componentsSeparatedByString:@";"];
        for (NSInteger i = 0; i < bigs.count; i++) {
            UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetWidth(self.scrollView.frame)* i, 0, CGRectGetWidth(self.scrollView.frame), CGRectGetHeight(self.scrollView.frame))];
             NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/%@?path=%@",ServerUrl,DearImage,bigs[i]]];
            [imageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"commentBG"]];
            [self.scrollView addSubview:imageView];
        }
        self.scrollView.contentSize = CGSizeMake(bigs.count * CGRectGetWidth(self.scrollView.frame), CGRectGetHeight(self.scrollView.frame));
    }else{
        self.scrollViewY.constant = 0;
        self.scrollViewH.constant = 0;
    }
    CGFloat conH = 0;
    if (self.contentLabel.text.length > 0) {
        conH = [CJJHelper textHeightFromString:self.contentLabel.text width:ScreenSize.width - 20 fontSize:15];
    }
    self.contentH.constant = conH + 10;
    [self layoutIfNeeded];
    self.totalH = CGRectGetMaxY(self.allLabel.frame) + 10;
}

@end
